//
//  BatchOptCell.m
//  ios-supplier
//
//  Created by feynmanyuan on 15/5/17.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "BatchOptCell.h"
#import "UIButton+SelectFix.h"

@interface BatchOptCell()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UIImageView *cellImageView;
@property (weak, nonatomic) IBOutlet UIButton *selectedChecker;
- (IBAction)btnClick:(id)sender;

@end

@implementation BatchOptCell
-(void)setMerchandise:(JFBMerchandiseDS *)merchandise{
    
    [((UIButton_SelectFix*)self.selectedChecker) setImage:[UIImage imageNamed:@"check2"] forButtonState:UIControlStateNormal];
    [((UIButton_SelectFix*)self.selectedChecker) setImage:[UIImage imageNamed:@"check2_on"] forButtonState:UIControlStateSelected];
    
    _merchandise = merchandise;
    //    [self.imageView setImage:[UIImage imageNamed:merchandise.imageURL]];
    [self.cellImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://wup.jufangbian.com/upload/product_image/product_100/%lu.jpg", (unsigned long)merchandise.mpId]] placeholderImage:[UIImage imageNamed:ImageDefaultPlaceholder]];
//    self.imageView.frame = CGRectMake(10, 10, 50, 50);
    self.nameLabel.text = merchandise.name;
    self.priceLabel.text = [NSString stringWithFormat:@"¥ %@", [NSString decimalToString:merchandise.storePrice]];
    
    self.selectedChecker.selected = [merchandise.mpURL isEqualToString:@"on"];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.cellImageView.bounds =CGRectMake(10,10, 50, 50);
    
    self.cellImageView.frame =CGRectMake(self.selectedChecker.bounds.size.width + kOrderCellSpacing * 2,  10, 50, 50);
    
    self.cellImageView.contentMode =UIViewContentModeScaleAspectFit;
}

- (IBAction)btnClick:(id)sender {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"merchandiseSelect" object:self userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%lu", (unsigned long)self.merchandise.mpId] forKey:@"merchandiseId"]];
}
@end
